package com.situ.gcbs.server.util;

/**
 * 功能：
 *
 * @author 千堆雪
 * @version 1.0.0
 * @since 2024/5/16
 * <p>
 * created by 千堆雪 on 2024/5/16 10:19, last modified by 千堆雪 on 2024/5/16 10:19
 */
public class Result {
    private boolean success = true;//后台是否执行成功
    private int code = 0;//状态码
    private String msg = "";//消息
    private Object data;//数据

    public Result(boolean success, int code) {
        this.success = success;
        this.code = code;
    }

    public Result(boolean success, int code, String msg) {
        this(success, code);
        this.msg = msg;
    }

    public Result(boolean success, int code, String msg, Object data) {
        this(success, code, msg);
        this.data = data;
    }

    public static Result success(int code, String msg, Object data) {
        return new Result(true, code, msg, data);
    }

    public static Result success(int code, String msg) {
        return new Result(true, code, msg);
    }

    public static Result success(int code) {
        return success(code, "");
    }

    public static Result success(Object data) {
        return success(200, "", data);
    }

    public static Result success() {
        return success(0);
    }

    public static Result failure(int code, String msg) {
        return new Result(false, code, msg);
    }

    public static Result failure(String msg) {
        return failure(500, msg);
    }

    public boolean isSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }
}
